import {ApiFetch} from "../api/apiHandler";
import {BaseUrl} from "../constant/constant";
import {message} from "antd";

class TopicModel {

    constructor() {
        this.url = BaseUrl
    }

    add(params) {
        let end = this.url + 'addhuati'
        let req = new ApiFetch(end)
        let fm = new FormData()
        const {
            title,
            txt,
            imgList,
            lock,
            uid,
        } = params

        if (title === '') {
            // message.error('标题不能为空')
            return new Promise((resolve, reject) => reject(false))
        }

        fm.append('title', title)
        fm.append('txt', txt)
        let clock = lock ? 1 : 0
        fm.append('clock', clock)
        fm.append('uid', uid)
        const imgs = []
        imgList.map(img => {
            imgs.push(img.name)
            fm.append(img.name, img)
        })
        fm.append('imgs', JSON.stringify(imgs))

        // for (let i = 0; i < Object.keys(params).length; i++) {
        //     let k = Object.keys(params)[i]
        //     let v = params[k]
        //     if (k === 'imgs') {
        //         v = JSON.stringify(v)
        //     }
        //     fm.append(k, v)
        // }
        // // fm.append('imgs', '[]')
        return req.fetch(fm)
    }

    all(params) {
        let end = this.url + 'gethuati'
        // let end = 'http://123.207.85.242/app/try/go/gethuati'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    addJH(params) {
        let end = this.url + 'addhuatijing'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    ding(params) {
        let end = this.url + 'addhuatiding'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    delete(params) {
        let end = this.url + 'delhuati'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    getLvLimit(params) {
        let end = this.url + 'gethuatilvlimit'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    setLvLimit(params) {
        let end = this.url + 'sethuatilvlimit'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    officialComment(params) {
        let end = this.url + 'huaticomment'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    comments(params) {
        let end = this.url + 'getcomment'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }
    deleteComment(params) {
        let end = this.url + 'delcomment'
        let req = new ApiFetch(end)
        return req.fetch(params)
    }
}

export default TopicModel
